package cc.w3d.jawos.apps.artiks.client;


import cc.w3d.jawos.apps.artiks.client.components.ArticleEditor;
import cc.w3d.jawos.apps.artiks.client.components.ResourceTreeItem;
import cc.w3d.jawos.apps.artiks.client.components.TreePanel;
import cc.w3d.jawos.apps.artiks.client.icons.Icons;
import cc.w3d.jawos.apps.artiks.client.rpc.ArtiksService;
import cc.w3d.jawos.apps.artiks.manager.client.beans.ResourceType;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SplitLayoutPanel;

public class Artiks implements EntryPoint
{
	public static ArtiksService service = new ArtiksService();

	public static Icons icons = GWT.create(Icons.class);

	ScrollPanel editPanel = new ScrollPanel();
	ArticleEditor articleEditor = new ArticleEditor();
	HTML gray = new HTML("<div style='width:100%; height:100%; background-color:#CCCCCC;'>&nbsp;</div>");
	
	public void onModuleLoad()
	{
		service.initService();
		articleEditor.loadCats();

		SplitLayoutPanel main = new SplitLayoutPanel();

		TreePanel treePanel = new TreePanel();

		treePanel.addSelectionHandler(new SelectionHandler<ResourceTreeItem>() {
			
			public void onSelection(SelectionEvent<ResourceTreeItem> event)
			{
				editPanel.clear();

				if(event.getSelectedItem().getType() == ResourceType.FOLDER)
					editPanel.add(gray);
				else
				{
					articleEditor.setSelectedTreeItem(event.getSelectedItem());
					editPanel.add(articleEditor);
				}
			}
		});

		main.addWest(treePanel, 250);

		/*<editPanel>*/

		gray.setWidth("100%");
		gray.setHeight("100%");

		editPanel.add(gray);

		editPanel.setHeight( "100%");
		editPanel.setWidth("100%");

		main.add(editPanel);
		/*</editPanel>*/

		RootLayoutPanel.get().add(main);
		main.setWidgetMinSize(treePanel, 200);
		treePanel.unfoldRoot();
	}
}
